/**
 * Copyright &copy; 2013-2015 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.modules.sys.entity;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;

import cn.net.ecode.common.persistence.TreeEntity;
import cn.net.ecode.common.persistence.annotation.Id;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 公司管理Entity
 * @author 冯伟、ThinkGem
 * @version 2014-8-19
 */
public class Company extends TreeEntity<Company> {
	
	private static final long serialVersionUID = 1L;
	private String companyCode;		// 公司编码
	private String companyName;		// 公司名称
	private String companyNameSimple;		// 公司简称
	private String viewCode;  		// 显示的代码名称 （仅作为显示用，集团内唯一）
	private Area area;		// 注册区域
	private Office office;		// 组织机构
	private String isHesuan;		// 是否独立核算（帐套）
	private String isChuzhang;		// 是否出账公司
	private String isHetong;		// 是否合同公司
	private String isJiaoyi;		// 是否交易公司

//	private String userCode;	// 根据用户编号查询授权的公司列表
	
	public Company() {
		super();
	}

	public Company(String id){
		super(id);
	}

//	public Company(User user){
//		this();
//		if (user != null){
//			this.userCode = user.getUserCode();
//		}
//	}
	
	public Company getParent() {
		return parent;
	}

	public void setParent(Company parent) {
		this.parent = parent;
	}

	@Id
	public String getCompanyCode() {
		return companyCode;
	}

	public void setCompanyCode(String companyCode) {
		this.companyCode = companyCode;
	}
	
	@Length(min=0, max=200, message="公司名称长度不能超过 200 个字符")
	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	
	@Length(min=0, max=100, message="公司简称长度不能超过 100 个字符")
	public String getCompanyNameSimple() {
		return companyNameSimple;
	}
	
	public void setCompanyNameSimple(String companyNameSimple) {
		this.companyNameSimple = companyNameSimple;
	}

	@Pattern(regexp="[a-zA-Z0-9_]{0,30}", message="编码长度不能大于 30 个字符，并且只能包含字母、数字、下划线")
	public String getViewCode() {
		return viewCode;
	}

	public void setViewCode(String viewCode) {
		this.viewCode = viewCode;
	}

	@NotNull(message="注册区域不能为空")
	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}
	
	public Office getOffice() {
		return office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}
	
	@Length(min=0, max=1, message="是否独立核算（帐套）长度不能超过 1 个字符")
	public String getIsHesuan() {
		return isHesuan;
	}

	public void setIsHesuan(String isHesuan) {
		this.isHesuan = isHesuan;
	}
	
	@Length(min=0, max=1, message="是否出账公司长度不能超过 1 个字符")
	public String getIsChuzhang() {
		return isChuzhang;
	}

	public void setIsChuzhang(String isChuzhang) {
		this.isChuzhang = isChuzhang;
	}
	
	@Length(min=0, max=1, message="是否合同公司长度不能超过 1 个字符")
	public String getIsHetong() {
		return isHetong;
	}

	public void setIsHetong(String isHetong) {
		this.isHetong = isHetong;
	}
	
	@Length(min=0, max=1, message="是否交易公司长度不能超过 1 个字符")
	public String getIsJiaoyi() {
		return isJiaoyi;
	}

	public void setIsJiaoyi(String isJiaoyi) {
		this.isJiaoyi = isJiaoyi;
	}

//	public String getUserCode() {
//		return userCode;
//	}
//
//	public void setUserCode(String userCode) {
//		this.userCode = userCode;
//	}

	/**
	 * Oracle字段过长限制,增加此方法,见UserDao.xml
	 * @return
	 */
	@JsonIgnore
	public String getCompanyNameS() {
		return getCompanyNameSimple();
	}
	
	/**
	 * Oracle字段过长限制,增加此方法,见UserDao.xml
	 * @return
	 */
	@JsonIgnore
	public void setCompanyNameS(String companyNameSimple) {
		setCompanyNameSimple(companyNameSimple);
	}
	
	@Override
	public String toString() {
		return companyCode;
	}
}